package dbUtil;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

public class Row {
    //将结果集转化为一个Bean对象
    public static <T> T toBean(ResultSet rs,Class<T> type) throws SQLException{
        return (T)ToBean.createBean(rs,type);
    }
    //将结果集转化为数组对象
    public static Object[] toArray(ResultSet rs) throws SQLException {
        //首先先创建一个数组。数组的长度就是数据库的列的大小
      Object[] objects=new Object[rs.getMetaData().getColumnCount()];
        for (int i = 0; i < objects.length; i++) {
            objects[i]=rs.getObject(i+1);
        }
      return null;
    }
    //将结果集转化为Map对象
    public static Map<String,Object> toMap(ResultSet rs) throws SQLException {
        Map<String, Object> map = new HashMap<String, Object>();
        ResultSetMetaData resultSetMetaData = rs.getMetaData();
        for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
            map.put(resultSetMetaData.getColumnLabel(i), rs.getObject(i));
        }
        return map;
    }
}
